using UnityEngine;

[ExecuteInEditMode]
public class ControllerTrampoline : ControllerGeneric
{
	private Vector3 fixedScale = new Vector3(2.25f, 0.125f, 2.25f);

	public float force = 20f;

	public Trampoline trampoline;

	public GameObject[] trampolineParts;

	private bool staticState;

	public override void OnLevelInPlace(Transform levelTransform)
	{
		base.OnLevelInPlace(levelTransform);
		if (levelTransform == base.transform.root)
		{
			PrepareForGame();
		}
	}

	public void PrepareForGame()
	{
		trampoline.SetForce(force);
		SetNames();
		SetParenting();
		base.name = "will_destroy_" + base.name;
		if (Application.isPlaying)
		{
			Object.Destroy(base.gameObject);
		}
		else
		{
			Object.DestroyImmediate(base.gameObject);
		}
	}

	private void Update()
	{
		if (Application.isEditor && !Application.isPlaying)
		{
			SetupRemoteControl();
			if (IsRemoteControlActive())
			{
				base.transform.position = remoteControl.transform.position;
				base.transform.rotation = remoteControl.transform.rotation;
			}
			if (remoteControl != null)
			{
				remoteControl.transform.localScale = fixedScale;
				remoteControl.scale = fixedScale;
			}
			Setup();
		}
	}

	private void Setup()
	{
		AssureParenting();
	}

	public void SetupRemoteControl()
	{
		if (remoteControl == null)
		{
			InitRemoteControl();
			remoteControl.gameObject.name = remoteControl.gameObject.name + base.name;
			remoteControl.gameObject.transform.position = base.transform.position;
			remoteControl.gameObject.transform.rotation = base.transform.rotation;
			remoteControl.gameObject.transform.localScale = fixedScale;
			remoteControl.gameObject.AddComponent<PresetsTrampoline>();
		}
	}

	public override void CopyFromRemoteControl(RemoteControl rc)
	{
		base.CopyFromRemoteControl(rc);
		CopyParentingFromRemoteControl(rc);
	}

	private void SetStatic(bool newStaticState = true)
	{
		if (newStaticState != staticState)
		{
			staticState = newStaticState;
			trampoline.gameObject.isStatic = newStaticState;
			GameObject[] array = trampolineParts;
			foreach (GameObject gameObject in array)
			{
				gameObject.isStatic = newStaticState;
			}
		}
	}

	private void SetParenting()
	{
		for (int childCount = base.transform.childCount; childCount > 0; childCount = base.transform.childCount)
		{
			base.transform.GetChild(0).parent = base.transform.parent;
		}
	}

	private void SetNames()
	{
		trampoline.gameObject.name = "Trampoline" + trampoline.gameObject.name;
		GameObject[] array = trampolineParts;
		foreach (GameObject gameObject in array)
		{
			gameObject.name = "Trampoline" + gameObject.name;
		}
	}
}
